package com.seata.controller;

import com.seata.entity.TUser;
import com.seata.remot.Callseate1Service;
import com.seata.service.TUserService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.gavin.core.domain.R;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * UserController
 *
 * @author grl
 * @date 2024/4/22
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class UserController {

    private final TUserService userService;

    private final Callseate1Service callseate1Service;

    @GlobalTransactional(name = "saveUser",rollbackFor = Exception.class)
    @PostMapping(value = "/seata/save")
    public R<Boolean> save(){
        callseate1Service.save();
        TUser user = new TUser();
        user.setAge(20);
        user.setUsername("张三");
        user.setCreateTime(LocalDateTime.now());
        user.setPassword("123456");
        boolean save = userService.save(user);
        int a = 0;
        int b = 6/a;
        return R.ok(save);
    }
}
